/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.gen2phen.labs.actions;

import java.util.ArrayList;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import org.gen2phen.labs.domain.Investigation;
import org.gen2phen.labs.domain.ObservableFeature;

/**
 *
 * @author pedrolopes
 *
 * GEN2PHEN Semantic Web Labs: Knowledge Mashup
 *
 */
@UrlBinding("/view")
public class ViewActionBean implements ActionBean {

    private ActionBeanContext context;
    private ArrayList<Investigation> invs = new ArrayList<Investigation>();
    private ArrayList<ObservableFeature> feats = new ArrayList<ObservableFeature>();

    public ArrayList<ObservableFeature> getFeats() {
        return feats;
    }

    public void setFeats(ArrayList<ObservableFeature> feats) {
        this.feats = feats;
    }

    public ArrayList<Investigation> getInvs() {
        return invs;
    }

    public void setInvs(ArrayList<Investigation> invs) {
        this.invs = invs;
    }

    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    public ActionBeanContext getContext() {
        return context;
    }

    /**
     * Loads all investigation from Pheno-OM using SPARQL and D2R endpoint.
     * Investigations are organized in a dynamic table in the client-side.
     *
     * @return Redirect to view.jsp
     */
    @DefaultHandler
    public Resolution doView() {

        // if investigations have been loaded, no need to reload everything again!
        if (org.gen2phen.labs.services.Loader.investigations().size() == 0) {
            org.gen2phen.labs.services.Loader.load();
        }

        // must be on global variable so that Stripes can access it in the .jsp
        invs = org.gen2phen.labs.services.Loader.investigations();
        return new ForwardResolution("/view.jsp");
    }
}
